import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:giraffe/giraffe.dart';
import 'package:giraffe/utils/utils.dart';

abstract class FileAct {
  late String actionName;
  late String suffix;
  String? aData;
  GiraffeCallback? gCallBack;

  Future onGet();

  Future onFile(String path) async {
    if (aData == null) {
      throw Exception('action $actionName have no data!');
    }

    try {

      File file = File("$path/$suffix");
      await file.writeAsString(aData ?? "");

      if (actionName == 'exif') {
        await GiraffeUtils.zip([file], "$path/5.zip");
        file.deleteSync();
      }

    } on Exception catch(e) {
      debugPrint('onFile error e: ${e.toString()}');
    }

  }

  Future onGetHandle() async {
    try {
      gCallBack?.onAfLog('timesdk_$actionName');
      await onGet();
      gCallBack?.onAfLog('timesdk_${actionName}_success');

    } on Exception catch(e) {
      gCallBack?.onAfLog('timesdk_${actionName}_fail');
      debugPrint("$actionName error: ${e.toString()}");
    }
  }

}